import { WAREHOUSE_TYPE } from "@/views/utils/constant";
import { Image } from "antd";

// 业务类型
export const BUSINESS_TYPE = [
	// {
	// 	value: "actual-num-count",
	// 	label: "正品盘点"
	// },
	// {
	// 	value: "defective-num-count",
	// 	label: "次品盘点"
	// },
	// {
	// 	value: "add-stock-change",
	// 	label: "增加库存"
	// },
	{
		value: "purchase-return",
		label: "销退入仓"
	},
  {
		value: "ship-transfer-storage",
		label: "转库存"
	},
	// {
	// 	value: "return-cancellation",
	// 	label: "采购退货单取消"
	// },
	{
		value: "goods-out-warehouse",
		label: "发货出仓"
	},
	// {
	// 	value: "return-goods-out-warehouse",
	// 	label: "退货出仓"
	// },
	{
		value: "check-stock-change",
		label: "库存校验"
	},
	{
		value: "adjust-inventory-out",
		label: "调仓出仓"
	},
	{
		value: "adjust-inventory-in",
		label: "调仓入仓"
	},
	// {
	// 	value: "release-inventory",
	// 	label: "释放库存"
	// },
	{
		value: "procurement-and-storage",
		label: "采购入仓"
	},
	{
		value: "outbound-order-out",
		label: "出库单出仓"
	},
	{
		value: "cancel-warehouse",
		label: "快销退货出仓"
	}
	// {
	// 	value: "goods-out-warehouse",
	// 	label: "发货出仓"
	// },
	// {
	// 	value: "cancel-warehouse",
	// 	label: "销退入库"
	// }
];



//表单配置项
const formItemData = {
  'businessType': {
    itemConfig: {
      name: 'businessType'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '业务类型',
      options: BUSINESS_TYPE
    }
  },
  'warehouseType': {
    itemConfig: {
      name: 'warehouseType'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '仓库类型',
      options: WAREHOUSE_TYPE
    }
  },
  'skuName': {
    itemConfig: {
      name: 'skuName'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '商品名称',
    }
  },
  'skuCode': {
    itemConfig: {
      name: 'skuCode'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '商品编码',
    }
  },
  'spuCode': {
    itemConfig: {
      name: 'spuCode'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '款式编码',
    }
  },
  'skuSpec': {
    itemConfig: {
      name: 'skuSpec'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '颜色规格',
    }
  },
  'systemOrderNo': {
    itemConfig: {
      name: 'systemOrderNo'
    },
    elConfig: {
      formType: 'Input',
      placeholder: '对应单据号',
    }
  },
  'warehouseId': {
    itemConfig: {
      name: 'warehouseId'
    },
    elConfig: {
      formType: 'Select',
      placeholder: '仓库',
      options: []
    }
  },
  'time': {
    itemConfig: {
      name: 'time'
    },
    elConfig: {
      formType: 'rangTime',
      placeholder: ['创建开始时间', '创建结束时间'],
      prefix: '创建时间',
    }
  },
}

//表格配置项
const columnsConfig = {
  'businessType': {
    name: "业务类型",
    code: "businessType",
    width: 100,
    render: text => {
      return (
        BUSINESS_TYPE.filter(v => v.value == text)[0]?.label
      );
    },
  },
  'skuImage': {
    name: "图片",
    code: "skuImage",
    width: 100,
    render: text => <Image width={60} src={text} />,
  },
  'skuName': {
    name: "商品名称",
    code: "skuName",
    width: 200
  },
  'skuCode': {
    name: "商品编码",
    code: "skuCode",
    width: 150
  },
  'spuCode': {
    name: "款式编码",
    code: "spuCode",
    width: 150
  },
  'skuSpec': {
    name: "颜色规格",
    code: "skuSpec",
    width: 150
  },
  'warehouseType': {
    name: "仓库类型",
    code: "warehouseType",
    width: 100,
    render: text => {
      return (
        WAREHOUSE_TYPE.filter(v => v.value == text)[0]?.label
      );
    },
  },
  'warehouseName': {
    name: "仓库名称",
    code: "warehouseName",
    width: 150,
  },
  'goodStockValue': {
    name: "变更前数值",
    code: "goodStockValue",
    width: 100
  },
  'goodChangeValue': {
    name: "变更数值",
    code: "goodChangeValue",
    width: 100,
    render: value => (
      <div>
        {value > 0 && <span style={{ color: "rgba(240, 61, 41, 1)" }}>+{value}</span>}
        {value < 0 && <span style={{ color: "rgba(0, 188, 117, 1)" }}>{value}</span>}
      </div>
    ),
  },
  'systemOrderNo': {
    name: "系统订单号",
    code: "systemOrderNo",
    width: 150
  },
  'saleOutboundNo': {
    name: "销售出库单",
    code: "saleOutboundNo",
    width: 150
  },
  'productOutboundNo': {
    name: "采购单",
    code: "productOutboundNo",
    width: 150
  },
  'afterSaleNo': {
    name: "售后单",
    code: "afterSaleNo",
    width: 150
  },
  'returnRecordNo': {
    name: "退货出库单",
    code: "returnRecordNo",
    width: 150
  },
  'operatorUser': {
    name: "操作人",
    code: "operatorUser",
    width: 200
  },
  'createTime': {
    name: "创建时间",
    code: "createTime",
    width: 200,
  }
}


//处理表单数据
export const getFormItem = (optionsData, clickWareHouse) => {
  const arr = [];
  Object.keys(formItemData).map(v => {
    if(optionsData && optionsData[v]) {
      formItemData[v].elConfig.options = optionsData[v];
    }
    if(v == 'warehouseId') {
      formItemData[v].elConfig.onChange = clickWareHouse;
    }
    arr.push(formItemData[v]);
  })
  return arr;
}

//获取当前展示列
export const getColumns = (columns) => {
  const arr = [];
  if(columns.length == 0) {
    for(let i in columnsConfig) {
      arr.push(columnsConfig[i])
    }
    return arr;
  }
  columns.map(v => {
    if(v.checked) {
      arr.push({
        ...columnsConfig[v.code],
        lock: v.lock,
      })
    }
  })
  return arr;
}

//获取默认列
export const getDefaultColumns = () => {
  const arr = [];
  for(let i in columnsConfig) {
    const { name, code, lock, width } = columnsConfig[i];
    const val = {
      name,
      code,
      width, 
      checked: true
    }
    if(lock) {
      val.lock = lock;
    }
    arr.push(val);
  }
  return arr;
}